package dao.admin.impl;

import com.mysql.cj.jdbc.ConnectionImpl;
import dao.BaseDao;
import dao.admin.ManagerEditDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * ManagerEditDaoImpl
 * 修改-更新管理员信息
 * @author ChenYanMei
 * @version 2023/9/5
 */
public class ManagerEditDaoImpl extends BaseDao implements ManagerEditDao {
    @Override
    public int update(String name, String password, String email, int id) {
        Connection conn = super.getConnection();
        PreparedStatement pstmt = null;
        int result = 0;
        String sql = "update manager set name=?, password=?, email=? where id=?";
        try {
            // 添加管理员
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, name);
            pstmt.setString(2, password);
            pstmt.setString(3, email);
            pstmt.setInt(4, id);
            result = pstmt.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            closeAll(null, pstmt, conn);
        }
        return result;
    }
}
